﻿using SmartPlant.Core;
using SmartPlant.Core.Mvvm;
using SmartPlant.Modules.Base.UIEntity;
using SmartPlant.Modules.Base.ViewModels;
using System.Collections.ObjectModel;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.Docking;
namespace SmartPlant.Modules.Base.Views
{
    /// <summary>
    /// SpecInput.xaml 的交互逻辑
    /// </summary>
    public partial class SpecInput : RadDocumentPane, IPaneModel, ICanClosedDocumentView
    {
        public SpecInput()
        {
            InitializeComponent();
        }

        public DockState Position => DockState.DockedLeft;

        private void RadButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            this.radGridView.BeginInsert();
        }

        private void radGridView_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
        {
            var viewModel = (SpecInputViewModel)DataContext;
            if (viewModel.Report == null)
            {
                e.Cancel = true;
                return;
            }
            var item = new SpecInputModel();
            item.ReportName = viewModel.Report.Name;
            e.NewObject = item;
        }

        private void RadDelete_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (this.radGridView.SelectedItems.Count == 0)
            {
                return;
            }
            ObservableCollection<SpecInputModel> itemsToRemove = new ObservableCollection<SpecInputModel>();
            foreach (var item in this.radGridView.SelectedItems)
            {
                itemsToRemove.Add(item as SpecInputModel);
            }
            foreach (var item in itemsToRemove)
            {
                ((ObservableCollection<SpecInputModel>)this.radGridView.ItemsSource).Remove(item as SpecInputModel);
            }
        }
    }
}
